﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestPlatform.Core;
using Aquiles.Helpers.Encoders;
using Aquiles.Cassandra10;
using Aquiles.Core.Cluster;
using Apache.Cassandra;
using Aquiles.Helpers;

namespace TestPlatform.Performer.Cassandra
{
    public class CassandraDeletePerformer : BaseDeletePerformer
    {
        public override string UnderlyinEngine { get { return "Cassandra"; } }

        public CassandraDeletePerformer()
            : base(new CassandraHelper())
        {

        }

        protected override void RemoveEntity(Guid id)
        {
            byte[] key = ByteEncoderHelper.GuidEncoder.ToByteArray(id);

            ColumnPath loginPath = new ColumnPath
            {
                Column = ByteEncoderHelper.UTF8Encoder.ToByteArray("login"),
                Column_family = CassandraHelper.UserCF,
            };

            ColumnPath namePath = new ColumnPath
            {
                Column = ByteEncoderHelper.UTF8Encoder.ToByteArray("name"),
                Column_family = CassandraHelper.UserCF,
            };

            ICluster cluster = AquilesHelper.RetrieveCluster("MGR-Cluster");
            cluster.Execute(new ExecutionBlock(c =>
            {
                c.remove(key, loginPath, UnixHelper.UnixTimestamp, ConsistencyLevel.ONE);
                c.remove(key, namePath, UnixHelper.UnixTimestamp, ConsistencyLevel.ONE);

                return null;
            }), "MGR");
        }
    }
}
